package com.wisezone.studentmanager.server.impl;

import java.util.List;

import com.wisezone.studentmanager.dao.UserDao;
import com.wisezone.studentmanager.model.User;
import com.wisezone.studentmanager.server.UserServer;
import com.wisezone.studentmanager.utils.MD5Util;

public class UserServerImpl implements UserServer {
	private UserDao userDao;

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public String register(String userName, String passWord, String headerUri) {

		// 检查用户是否已经注册
		boolean isCheck = userDao.checkUser(userName);
		if (isCheck) {
			return "用户已经注册!";
		}
		// 注册新用户
		User user = new User(userName, MD5Util.md5Encode(passWord, userName), headerUri);
		userDao.addUser(user);
		return "注册成功！";
	}

	@Override
	public User login(String userName, String passWord) {
		User user = userDao.getUser(userName, MD5Util.md5Encode(passWord, userName));
		return user;
	}

	@Override
	public List<User> getUserLists() {
		return userDao.getUserLists();
	}

	@Override
	public List<User> getUserLists(int startIndex, int pageSize) {
		return userDao.getUserLists(startIndex, pageSize);
	}

	@Override
	public int getTotalCount() {
		return userDao.getTotalCount();
	}

	@Override
	public int getTotalCount(int sex, String name, int age) {
		return userDao.getTotalCount(sex, name, age);
	}

	@Override
	public List<User> getUserLists(int sex, String userName, int age, int startIndex, int pageSize) {
		return userDao.getUserLists(sex, userName, age, startIndex, pageSize);
	}

}
